#include "str_list.h"
#include <stdlib.h>

struct str_list *str_list_vide(){
  struct str_list *l = malloc(sizeof(struct str_list));
  l->ret = NULL;
  return l;
}

struct str_list *str_list_ajouter(struct str_list*l,struct ret* c){
  if(l->ret == NULL || l == NULL){
    l->ret = malloc(sizeof(*l->ret));
    l->ret->val = malloc(1+strlen(c->val)*sizeof(char));
    l->ret->cmd = malloc(1+strlen(c->cmd)*sizeof(char));
    strcpy(l->ret->val,c->val);
    strcpy(l->ret->cmd,c->cmd);
    l->next = NULL;
  }
  else{
    struct str_list *tmp = l;
    while (tmp->next != NULL){
      tmp = tmp->next;
    }
    tmp->next->ret->val = malloc(1+strlen(c->val)*sizeof(char));
    tmp->next->ret->cmd = malloc(1+strlen(c->cmd)*sizeof(char));
    strcpy(tmp->next->ret->val,c->val);
    strcpy(tmp->next->ret->cmd,c->cmd);
    tmp->next->next = NULL;
    l = tmp;
}
  return l; 
}
